//
//  HWHomeHeader.swift
//  HWPromoteProjectAPP
//
//  Created by 王昌健 on 2022/1/24.
//  Copyright © 2022 王昌健. All rights reserved.
//

import UIKit

class HWHomeHeader: UICollectionReusableView {
    
    var imageView:UIImageView!
    var titleLabel:UILabel!
    var rightBgView:UIView!
    var rightTitleLabel:UILabel!
    var rightArrowImage:UIImageView!
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        initUI()
        
        initFrame()
        
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}

extension HWHomeHeader {
    private func initUI() -> Void {
        
        backgroundColor = .clear
        
        imageView = UIImageView()
        addSubview(imageView)
        
        titleLabel = HWLabel.createBoldLabel(title: "数据播报", color: "#333333", font: 16*widthScale)
        addSubview(titleLabel)
        
        rightBgView = UIView()
        rightBgView.backgroundColor = .white
        rightBgView.layer.cornerRadius = 14*widthScale
        rightBgView.layer.borderWidth = 1
        rightBgView.layer.borderColor = UIColor.colorWithHexString(hexString: "#EEEEEE").cgColor
        addSubview(rightBgView)
        
        rightTitleLabel = HWLabel.createLabel(title: "今日数据", color: "#333333", font: 14*widthScale)
        rightBgView.addSubview(rightTitleLabel)
        
        rightArrowImage = UIImageView()
        rightArrowImage.image = UIImage(named: "downArrow")
        rightBgView.addSubview(rightArrowImage)
        rightBgView.isHidden = true
    }
    
    private func initFrame() -> Void {
        imageView.snp.makeConstraints { make in
            make.left.equalTo(20*widthScale)
            make.centerY.equalToSuperview()
            make.width.height.equalTo(20*widthScale)
        }
        
        titleLabel.snp.makeConstraints { make in
            make.left.equalTo(imageView.snp.right).offset(6*widthScale)
            make.centerY.equalToSuperview()
        }
        
        rightBgView.snp.makeConstraints { make in
            make.right.equalTo(-20*widthScale)
            make.height.equalTo(28*widthScale)
            make.centerY.equalTo(imageView)
        }
        
        rightTitleLabel.snp.makeConstraints { make in
            make.left.equalTo(10*widthScale)
            make.centerY.equalToSuperview()
        }
        
        rightArrowImage.snp.makeConstraints { make in
            make.centerY.equalToSuperview()
            make.left.equalTo(rightTitleLabel.snp.right).offset(10*widthScale)
            make.right.equalTo(-10*widthScale)
            make.width.height.equalTo(16*widthScale)
        }
    }
}
